﻿@using ATTools.Helpers;
@{
	Script.Require("jQuery").AtFoot();
	Script.Require("AudioPlayer").AtFoot();
    Style.Require("Sound").AtFoot();
}

@{
	string audioUrl = String.Empty;
	if (Model.UseCustomSound)
	{
		audioUrl = Model.CustomSoundString;
	} 
	else
	{
		audioUrl = Model.SoundString;
	}
	int idHash = 0;
	if (audioUrl != null)
	{
		idHash = audioUrl.GetHashCode();
	}
	else
	{ 
		idHash = new Random().Next();
	}
	
}
<span id="audioplayer@{@idHash}" class="audioplayer">
	<audio src="@audioUrl" class="audioElement" preload="none"></audio>
	<span class="soundControl">
		<span>@T("Sound player:")</span>
		<a href="#" class="play">@T("Play")</a>
		<a href="#" class="pause" style="display:none">@T("Pause")</a>
		<a href="#" class="stop" style="display:none">@T("Stop")</a>
	</span>
    <a class="soundLink" href="@audioUrl">(@T("Download"))</a>
</span>


@using (Script.Foot()) {
<script type="text/javascript">
(function ($) {
	$(document).ready(function () {
		$('#audioplayer@{@idHash}').audioPlayer({
			audioUrl: '@audioUrl',
			playType: '@Html.Raw(AudioSupportHelper.GetPlayType(audioUrl))'
		});

		$("body").keyup(function (event) {
			if (event.altKey) {
				if (event.which == '80') {
					$(".audioplayer:first .play:visible, .audioplayer:first .pause:visible").click();
				} else if (event.which == '83') {
					$(".audioplayer:first .stop:visible").click();
				}
			}
		});
	});
})(jQuery);
</script>
}